const opentoken = require("jsonwebtoken");
const str = "xfhhxhdfhxhxhxhxhxh"; //用于签名
// 创建token
function createToken(obj) {
    obj.time = Date.now();
    return opentoken.sign(obj, str, { expiresIn: 60 * 60 });
}


// 验证token
function checkToken(token) {
    return new Promise((resolve, reject) => {
        opentoken.verify(token, str, (err, data) => {
            if (err) {
                reject(err);
            } else {
                resolve(data);
            }
        })
    })
}

module.exports = { createToken, checkToken };